package cwb1;

import javax.servlet.http.*;

import com.google.appengine.api.datastore.EntityNotFoundException;

import java.io.IOException;



public class loginServlet extends HttpServlet
{
	
	public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException
			{
				String id = req.getParameter("username");
				String password = req.getParameter("password");
				String url = req.getParameter("url");

				String boodschap = null;

				try {				
				
					boolean test = UserRegistry.getInstance().verifyPassword(id,password);
					if(test==true)
					{
						resp.sendRedirect(url);
						req.getSession().setAttribute("id", id);
						
					}
				
					else
					{
						boodschap = "The username or password you entered is incorrect.";
						resp.sendRedirect("login.jsp?boodschap=" + boodschap);
					}
					
					
					}
				
				catch (EntityNotFoundException e) {
					boodschap = "The username or password you entered is incorrect.";
					resp.sendRedirect("login.jsp?boodschap=" + boodschap);
				}
				
			}	
}